<template>
	<view class="container">
		<tui-navigation-bar @init="initNavigation" :isOpacity="false" :maxOpacity="1" :scrollTop="scrollTop"
			backgroundColor="#fff" color="#333" :title="pageTitle">
			<view class="tui-header" :style="{ marginTop: navBarTop + 'px' }">
				<view class="get-back dy-iconfont icon-qiehuanqizuo" @click="goBack('pages/user/index')"></view>
			</view>
		</tui-navigation-bar>
		<view class="main">
			<view class="appraise-tab ">
				<view class="tab" :class="{'active':item.id == appraiseTab.current}"
					v-for="(item,index) in appraiseTab.tab" :key="item.id" @tap.stop.prevent="selecTab(item.id)">
					{{item.value}}
				</view>
			</view>
			<view class="main-loading">
				<uv-loading-icon :show="!appraise.loading" :size="28" timing-function="linear"
					mode="circle"></uv-loading-icon>
			</view>
			<view class="appraise-list" v-if="appraise.list.length > 0">
				<view class="appraise-item" v-for="(item ,index) in appraise.list" :key="item.id"
					:class="{'noBorder': index == appraise.list.length - 1}">
					<view class="post">
						<view class="post-info">
							<view class="head">
								<image :src="item.avatar" mode="aspectFill"
									:style="{'width': '90rpx','height': '90rpx',borderRadius: '50%'}">
								</image>
							</view>
							<view class="user-info" :style="'width: calc(100% - '+ '90rpx' +' - 16rpx);'">
								<view class="user-info-header">
									<view class="user-name onelist-hidden">
										{{item.nickName}}
									</view>
									<view class="recommend" v-if="item.auditState == 1"
										:class="{'no_recommend': item.recommendState == 0}">
										{{item.recommendState == 0 ? '不推荐':'推荐'}}
									</view>
									<view class="auditing" v-if="item.auditState == 2">审核中</view>
									<view class="audit-f" v-if="item.auditState == 3">审核失败</view>
								</view>
								<view class="data">{{item.createTime}}</view>
							</view>
						</view>
						<view class="content">{{item.content}}</view>
						<image-arrange v-if="item.forumPictureList" :imageList="item.forumPictureList" :isPadLeft="true"
							:basicsWidth="widthrpx" :basicsWidthPx="basicsWidthPx"></image-arrange>
						<view class="order">
							<view class="order-box">
								<view class="order-per">
									<text style="flex-shrink: 0;">派给</text>
									<text class="name onelist-hidden">「{{item.receiveNickName}}」</text>
									<text style="flex-shrink: 0;">的订单</text>
								</view>
								<view class="order-time">创建时间：{{item.orderCreateTime}}</view>
							</view>
						</view>
						<view v-if="appraiseTab.current == 'my'" class="delete" @tap="onDelete(item,index)">删除</view>
					</view>
				</view>
			</view>
			<view v-show="appraise.loading && appraise.list.length <= 0">
				<empty
					:image="'https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/empty/empty-appraise.png'"
					fixed>
					{{appraiseTab.current == 'my'?'还没评价过，留点足迹吧': '还没收到评价'}}
				</empty>
			</view>
			<view v-show="load.loading">
				<uv-load-more :status="load.status" :loading-text="load.loadingText" :nomore-text="load.nomoreText"
					:line="load.status == 'nomore'" />
			</view>
		</view>
		<uv-toast ref="toast"></uv-toast>
		<uv-popup :safeAreaInsetBottom="false" ref="popup" mode="bottom" round="20">
			<view class="delete-pop">
				<view class="header">
					<view class="title"></view>
					<view class="close" @tap="close"><text class="dy-iconfont icon-a-bianzu69"></text></view>
				</view>
				<view class="delete-hint">确认要删除评价吗？</view>
				<view class="btn-box">
					<view class="look" @tap="close">取消</view>
					<button class="btn-primary btn-submit" @tap.stop.prevent="onSubmit">确认</button>
				</view>
			</view>
		</uv-popup>
		<survey-pop></survey-pop>
	</view>
</template>

<script>
	import mp from "@/mixins/mp.js";
	const app = getApp();
	export default {
		mixins: [mp],
		options: {
			styleIsolation: 'shared'
		}, //解决/deep/不生效**
		components: {},
		data() {
			return {
				navBarOpacity: 0, //标题图标距离顶部距离
				scrollTop: 0.5, //页面滚动高度
				navBarTop: 0, // 导航栏content顶部m-top
				skeletonShow: true, //加载
				pageTitle: '我的评价', //标题
				apse: null,
				appraise: {
					list: [],
					hasMore: false,
					loading: true,
					page: 1,
				},
				load: {
					loading: false,
					status: 'loading',
					loadingText: '努力加载中',
					nomoreText: '没有更多了'
				},
				appraiseTab: {
					tab: [{
						value: '我评价的',
						id: 'my'
					}, {
						value: '我收到的',
						id: 'receive'
					}],
					current: 'my'
				},
				widthrpx: 0,
				rpx: app.globalData.widthPx / 750,
				basicsWidthPx: '',
			};
		},
		/**
		 * 计算属性
		 */
		computed: {},
		onLoad(options) {
			this.getPageData()
		},
		onShow: function() {
			this.widthrpx = app.globalData.systemInfo.windowWidth / this.rpx - 24 * 2 - 106
			this.basicsWidthPx = ['web', 'h5'].includes(app.globalData.systemInfo.uniPlatform) ? -(this.widthrpx * this
				.rpx) + 'px' : (-this.widthrpx) + 'rpx'
		},
		/**
		 * 下拉
		 */
		onPullDownRefresh: function() {
			this.appraise.page = 1
			this.getPageData()
		},
		/**
		 * 触底
		 */
		onReachBottom() {
			if (this.appraise.hasMore && this.appraise.loading) {
				this.load.loading = true
				this.getPageData()
			}
		},
		/**
		 * 滚动
		 */
		onPageScroll(res) {
			this.scrollTop = res.scrollTop;
		},
		methods: {
			goLogin() {
				app.doLogin()
			},
			initNavigation(e) {
				this.navBarOpacity = e.opacity;
				this.navBarTop = e.top;
			},
			// 返回上一页
			goBack: function(url) {
				if (url) {
					app.navigationTo(url)
				} else {
					app.beNavigateBack();
				}
			},
			// 加载页面数据
			getPageData: function(callback) {
				Promise.all([this.requestPengList()]).then(() => {
					// this.skeletonShow = false;
					uni.stopPullDownRefresh();
				});
			},
			requestPengList() {
				return new Promise((resolve, reject) => {
					this.appraise.loading = false
					app._post_form(
						"/client/my/order-forum-page", {
							current: this.appraise.page,
							extra: {},
							model: {
								dataType: this.appraiseTab.current == 'my' ? 0 : 1,
							},
							order: "descending",
							size: 10,
							sort: "createTime"
						},
						(result) => {
							let {
								records,
								total
							} = result.data;
							let {
								page,
								list,
								hasMore
							} = this.appraise;
							if (1 == page) {
								list.length = 0;
							}
							list = [...list, ...records];
							hasMore = total > list.length;
							this.appraise.list = list;
							this.appraise.hasMore = hasMore;
							if (hasMore) {
								page++;
								this.load.loading = false
							} else if (list.length > 3) {
								this.load.loading = true
								this.load.status = 'nomore'
							} else {
								this.load.status = 'nomore'
							}
							this.appraise.page = page;
						}, null, () => {
							resolve();
							this.appraise.loading = true
						}
					);
				});
			},
			onDelete(item, index) {
				this.apse = {
					item: item,
					index: index
				}
				this.$refs.popup.open();
			},
			close() {
				this.$refs.popup.close();
			},
			onSubmit() {
				return new Promise((resolve, reject) => {
					this.$refs.toast.show({
						type: 'loading',
					})
					app._post_form(
						"/client/my/remove/order-forum", this.apse.item.id,
						(result) => {
							this.$refs.toast.hide()
							this.close()
							this.appraise.list.splice(this.apse.index, 1);
							setTimeout(() => {
								this.$refs.toast.show({
									type: 'success',
									message: "删除成功"
								})
								setTimeout(() => {
									this.$refs.toast.hide()
								}, 1000)
							}, 200)
						}, null, () => {
							this.close()
							this.$refs.toast.hide()
							resolve();
						}
					);
				});
			},
			selecTab(id) {
				if (id != this.appraiseTab.current) {
					this.appraiseTab.current = id
					this.load.loading = false
					this.appraiseTab.page = 1
					this.appraiseTab.list = []
					this.requestPengList()
				}
			}
		},
	};
</script>
<style lang="scss" scoped>
	.container {
		min-height: 100vh;
		background: #FFF;

		.tui-header {
			width: 100%;
			position: fixed;
			top: 0;
			padding: 0 42rpx;
			display: flex;
			align-items: center;
			height: 32px;
			transform: translateZ(0);
			z-index: 99999;
			box-sizing: border-box;

			.get-back {
				flex-shrink: 0;
				width: 36rpx;
				height: 36rpx;
				color: #000;
				font-size: 36rpx;
				padding: 2rpx 40rpx 2rpx 2rpx;
			}
		}

		.main {
			box-sizing: border-box;
			padding: 280rpx 0 66rpx;



			.appraise-tab {
				position: fixed;
				z-index: 2;
				width: 100%;
				top: 91px;
				display: flex;
				align-items: center;
				box-sizing: border-box;
				padding: 30rpx 48rpx;
				background: #FFFFFF;
				box-shadow: 2rpx 10rpx 20rpx -8rpx rgba(198, 204, 202, 0.3);

				.tab {
					font-size: 30rpx;
					font-weight: 900;
					color: #999999;
					line-height: 44rpx;
					margin-right: 28rpx;
					transition: all 0.3s;


					&.active {
						font-size: 32rpx;
						font-weight: 900;
						color: #222222;
						line-height: 44rpx;
					}
				}
			}

			.main-loading {
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translateX(-50%);
			}

			.appraise-list {
				box-sizing: border-box;
				padding: 0 32rpx 0;


				.appraise-item {
					box-sizing: border-box;
					padding-bottom: 37rpx;
					margin-top: 23rpx;
					border-bottom: 2rpx solid #E3E9E5;

					&.noBorder {
						border: none;
					}
				}

				.post {
					.post-info {
						display: flex;
						width: 100%;
						margin-bottom: 16rpx;

						.head {
							flex-shrink: 0;
							margin-right: 16rpx;
						}

						&.dynamic {
							.user-info {
								.user-info-header {
									flex-direction: column;
									align-items: flex-start;
								}
							}
						}

						.user-info {
							display: flex;
							align-items: center;
							flex-wrap: wrap;

							.user-info-header {
								display: flex;
								align-items: center;
								justify-content: space-between;
								margin-bottom: 5rpx;
								width: 100%;

								.user-name {
									font-size: 28rpx;
									font-weight: 900;
									color: #222222;
									line-height: 44rpx;
									margin-right: 20rpx;
								}

								.data {
									font-size: 24rpx;
									font-weight: 400;
									color: #999999;
									line-height: 44rpx;
									flex-shrink: 0;
								}

								.recommend {
									flex-shrink: 0;
									box-sizing: border-box;
									padding: 1rpx 15rpx 1rpx 42rpx;
									background: linear-gradient(270deg, #D3FB33 0%, rgba(167, 245, 23, 0) 100%);
									border-radius: 30rpx;
									line-height: 33rpx;
									font-size: 24rpx;
									font-weight: 400;
									color: #282D2D;
									position: relative;

									&::before {
										content: "";
										display: block;
										width: 48rpx;
										height: 48rpx;
										background-image: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/community/recommend.png');
										background-size: 100%;
										position: absolute;
										left: -10rpx;
										bottom: 50%;
										transform: translateY(50%);
									}

									&.no_recommend {
										background: linear-gradient(270deg, #FF4664 0%, rgba(255, 70, 100, 0) 100%);

										&::before {
											background-image: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/community/no_ recommend.png');
										}
									}
								}

								.auditing,
								.audit-f {
									flex-shrink: 0;
									box-sizing: border-box;
									padding: 1rpx 15rpx 1rpx 42rpx;
									background: linear-gradient(270deg, #FFBF12 0%, rgba(255, 191, 18, 0) 100%);
									border-radius: 30rpx;
									line-height: 33rpx;
									font-size: 24rpx;
									font-weight: 400;
									color: #282D2D;
									position: relative;

									&::before {
										content: "";
										display: block;
										width: 48rpx;
										height: 48rpx;
										background-image: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/community/no_rz.png');
										background-size: 100%;
										position: absolute;
										left: -10rpx;
										bottom: 50%;
										transform: translateY(50%);
									}
								}

								// .audit-f{}
							}

							.data {
								font-size: 24rpx;
								font-weight: 400;
								color: #999999;
								line-height: 44rpx;
								flex-shrink: 0;
							}
						}
					}

					.content {
						box-sizing: border-box;
						padding-left: 106rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #222222;
						line-height: 44rpx;
						margin-bottom: 16rpx;
					}

					.image-list {
						padding-left: 106rpx;
					}

					.order {
						box-sizing: border-box;
						padding-left: 106rpx;
						margin-top: 24rpx;

						.order-box {
							width: 100%;
							box-sizing: border-box;
							padding: 24rpx 28rpx;
							background: #F6F8F7;
							border-radius: 12rpx;
						}

						.order-per {
							max-width: 80%;
							font-size: 28rpx;
							font-weight: 900;
							color: #222222;
							line-height: 44rpx;
							display: flex;
							align-items: center;

							.name {
								display: inline-block;
								max-width: 60%;
							}
						}

						.order-time {
							font-size: 24rpx;
							font-weight: 400;
							color: #222222;
							line-height: 44rpx;
							margin-top: 4rpx;
						}
					}

					.delete {
						width: 100rpx;
						height: 36rpx;
						background: #FFFFFF;
						border-radius: 20rpx;
						border: 2rpx solid #7B867F;
						font-size: 24rpx;
						font-weight: 400;
						color: #999B9B;
						line-height: 36rpx;
						text-align: center;
						margin-top: 16rpx;
						margin-left: auto;
					}
				}
			}
		}

		.delete-pop {
			background: #FFFFFF;
			box-sizing: border-box;
			padding: 43rpx 31rpx 66rpx;
			position: relative;

			.header {
				display: flex;
				align-items: center;
				justify-content: space-between;
				box-sizing: border-box;

				.title {
					font-size: 32rpx;
					font-weight: 900;
					color: #282D2D;
					line-height: 45rpx;
				}

				.close {
					font-size: 22rpx
				}
			}

			.delete-hint {
				font-size: 32rpx;
				font-weight: 900;
				color: #282D2D;
				line-height: 45rpx;
				margin: 27rpx 0 49rpx 0;
				text-align: center;
			}

			.btn-box {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.look {
					width: calc((100% - 24rpx)/2);
					background: #FFFFFF;
					border-radius: 20rpx;
					border: 2rpx solid #7B867F;
					font-size: 32rpx;
					font-weight: 900;
					color: #999B9B;
					height: 84rpx;
					line-height: 84rpx;
					text-align: center;
				}

				.btn-submit {
					width: calc((100% - 24rpx)/2);
					// height: 102rpx;
					// line-height: 102rpx;
				}
			}
		}
	}
</style>